package com.kc.demo.kcapidemo.web;

import com.alibaba.fastjson.JSONObject;
import com.kc.demo.kcapidemo.demo.CustomizedWebSocketClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Controller
@RequestMapping(value = "/socket")
public class WebSocketController {

    @Autowired
    private WebSocketDemo websocketServerCustomized;

    @Autowired
    private CustomizedWebSocketClient socketClient;

    @ResponseBody
    @GetMapping(value = "/message")
    public void getSocketMessage() throws IOException {
        JSONObject json = new JSONObject();
        json.put("to", "ddd");
        json.put("msg", "欢迎连接WebSocket！！！！");
        websocketServerCustomized.sendMessageAll(json.toJSONString());
    }
}